class Util {
  static sleep (millisecond) {
    return new Promise(
      (resolve) => {
        setTimeout(
          resolve,
          millisecond
        );
      }
    );
  }

  static dateFormatter(date, format) {
    let dateString = format;
    dateString = dateString.replace(/YYYY/g, date.getFullYear());
    dateString = dateString.replace(/MM/g, (date.getMonth() + 1).toString().padStart(2, '0'));
    dateString = dateString.replace(/DD/g, date.getDate().toString().padStart(2, '0'));
    dateString = dateString.replace(/hh/g, date.getHours().toString().padStart(2, '0'));
    dateString = dateString.replace(/mm/g, date.getMinutes().toString().padStart(2, '0'));
    dateString = dateString.replace(/ss/g, date.getSeconds().toString().padStart(2, '0'));

    return dateString;
  }
}

module.exports = Util;